<?php

namespace app\index\controller;

use think\Db;

class SaleVideo
{
    /**
     * 活动视频数据
     * @return \think\response\Jsonp
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function videoDataNum(){
        $data = request()->param();
        $where = array('sale_id' => $data['id']);
        $data = Db::name('member_video')
            ->field('SUM(avg_play_duration) AS avg_play_duration , SUM(total_comment) AS total_comment , SUM(total_like) AS total_like , SUM(total_play) AS total_play , SUM(total_share) AS total_share')
            ->where($where)
            ->find();

        $data['avg_play_duration'] = floatval($data['avg_play_duration']);
        $data['total_comment'] = intval($data['total_comment']);
        $data['total_like'] = intval($data['total_like']);
        $data['total_play'] = intval($data['total_play']);
        $data['total_share'] = intval($data['total_share']);
        $data['usernum'] = Db::name('member_sale')->where($where)->count();
        $data['cardnum'] = Db::name('sale_card')->where($where)->sum('receive_num');
        $where['status'] = 1;
        $data['cardstatus1num'] = Db::name('user_card')->where($where)->count();
        $where['status'] = 0;
        $data['cardstatus0num'] = Db::name('user_card')->where($where)->count();
        return jsonp($data);
    }
}